﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Transactions;
using System.Text.RegularExpressions;
using MySql.Data.MySqlClient;
using tmAsk.Common;

namespace tmAsk.Webs
{
    public partial class pton : System.Web.UI.Page
    {
        tmAsk.Data.MakeHtml make = new tmAsk.Data.MakeHtml();
        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();

        public string con = "server=61.136.252.201;user=xelnage;database=leave;port=3306;password=10816555;";

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("aaaaaaaaaaaaa" + "</br>");
        }

        public int getclassid(string oldclassname)
        {
            if (oldclassname == "手机短信") oldclassname = "其他";
            if (oldclassname == "系统") oldclassname = "其他";
            if (oldclassname == "测试账户") oldclassname = "其他";
            tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();
            string sql1 = "SELECT * FROM B_askClass WHERE a_classLevel = 2 and a_className = '" + oldclassname + "'";
            DataTable dt1 = SQL.GetList(sql1).Tables[0];
            return Convert.ToInt32(dt1.Rows[0]["a_classid"]);
        }

        //导入user表
        public void datauser()
        {
            MySqlConnection myConnection = new MySqlConnection(con);
            string query = "select * from user";
            MySqlDataAdapter da = new MySqlDataAdapter(query, myConnection);
            DataSet MyDataSet = new DataSet();
            da.Fill(MyDataSet);
            DataTable dt = MyDataSet.Tables[0];

            DataTable dtt = new DataTable("cart");
            DataColumn dc1 = new DataColumn("u_id", Type.GetType("System.Int32"));
            DataColumn dc2 = new DataColumn("u_order", Type.GetType("System.Int32"));
            DataColumn dc3 = new DataColumn("u_state", Type.GetType("System.Int32"));
            DataColumn dc4 = new DataColumn("u_name", Type.GetType("System.String"));
            DataColumn dc5 = new DataColumn("u_pass", Type.GetType("System.String"));
            DataColumn dc6 = new DataColumn("u_key", Type.GetType("System.String"));
            DataColumn dc7 = new DataColumn("u_branch", Type.GetType("System.String"));
            DataColumn dc8 = new DataColumn("u_rank", Type.GetType("System.String"));
            DataColumn dc9 = new DataColumn("u_level", Type.GetType("System.Int32"));
            dtt.Columns.Add(dc1);
            dtt.Columns.Add(dc2);
            dtt.Columns.Add(dc3);
            dtt.Columns.Add(dc4);
            dtt.Columns.Add(dc5);
            dtt.Columns.Add(dc6);
            dtt.Columns.Add(dc7);
            dtt.Columns.Add(dc8);
            dtt.Columns.Add(dc9);
            // dt.DefaultView.Count
            for (int i = 0; i < dt.DefaultView.Count; i++)
            {
                DataRow dr = dtt.NewRow();
                dr["u_id"] = dt.Rows[i]["u_id"];
                dr["u_order"] = dt.Rows[i]["u_order"];
                dr["u_state"] = dt.Rows[i]["u_state"];

                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_name"]) == "")
                {
                    dr["u_name"] = null;
                }
                else
                {
                    dr["u_name"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_name"]);
                }

                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_pass"]) == "")
                {
                    dr["u_pass"] = null;
                }
                else
                {
                    dr["u_pass"] = unpassat(System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_pass"]));
                }

                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_key"]) == "")
                {
                    dr["u_key"] = null;
                }
                else
                {
                    dr["u_key"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_key"]);
                }

                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_branch"]) == "")
                {
                    dr["u_branch"] = null;
                }
                else
                {
                    dr["u_branch"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_branch"]);
                }

                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_rank"]) == "")
                {
                    dr["u_rank"] = null;
                }
                else
                {
                    dr["u_rank"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["u_rank"]);
                }

                dr["u_level"] = dt.Rows[i]["u_level"];
                dtt.Rows.Add(dr);
            }

            BatchAdd(dtt, "l_user");
        }

        //导入book表
        public void databook()
        {
            MySqlConnection myConnection = new MySqlConnection(con);
            string query = "select * from book";
            MySqlDataAdapter da = new MySqlDataAdapter(query, myConnection);
            DataSet MyDataSet = new DataSet();
            da.Fill(MyDataSet);
            DataTable dt = MyDataSet.Tables[0];

            DataTable dtt = new DataTable("cart");
            DataColumn dc1 = new DataColumn("b_id", Type.GetType("System.Int32"));
            DataColumn dc2 = new DataColumn("b_rid", Type.GetType("System.Int32"));
            DataColumn dc3 = new DataColumn("b_look", Type.GetType("System.Int32"));
            DataColumn dc4 = new DataColumn("b_lookaddr", Type.GetType("System.String"));
            DataColumn dc5 = new DataColumn("b_branch", Type.GetType("System.String"));
            DataColumn dc6 = new DataColumn("b_title", Type.GetType("System.String"));
            DataColumn dc7 = new DataColumn("b_titlelen", Type.GetType("System.Int32"));
            DataColumn dc8 = new DataColumn("b_content", Type.GetType("System.String"));
            DataColumn dc9 = new DataColumn("b_name", Type.GetType("System.String"));
            DataColumn dc10 = new DataColumn("b_tel", Type.GetType("System.String"));
            DataColumn dc11 = new DataColumn("b_mail", Type.GetType("System.String"));
            DataColumn dc12 = new DataColumn("b_timein", Type.GetType("System.DateTime"));
            DataColumn dc13 = new DataColumn("b_timeup", Type.GetType("System.DateTime"));
            DataColumn dc14 = new DataColumn("b_address", Type.GetType("System.String"));
            DataColumn dc15 = new DataColumn("b_state", Type.GetType("System.Int32"));
            DataColumn dc16 = new DataColumn("b_reply", Type.GetType("System.Int32"));
            DataColumn dc17 = new DataColumn("b_replystate", Type.GetType("System.Int32"));
            DataColumn dc18 = new DataColumn("b_trial", Type.GetType("System.Int32"));
            dtt.Columns.Add(dc1);
            dtt.Columns.Add(dc2);
            dtt.Columns.Add(dc3);
            dtt.Columns.Add(dc4);
            dtt.Columns.Add(dc5);
            dtt.Columns.Add(dc6);
            dtt.Columns.Add(dc7);
            dtt.Columns.Add(dc8);
            dtt.Columns.Add(dc9);
            dtt.Columns.Add(dc10);
            dtt.Columns.Add(dc11);
            dtt.Columns.Add(dc12);
            dtt.Columns.Add(dc13);
            dtt.Columns.Add(dc14);
            dtt.Columns.Add(dc15);
            dtt.Columns.Add(dc16);
            dtt.Columns.Add(dc17);
            dtt.Columns.Add(dc18);
            // dt.DefaultView.Count
            for (int i = 0; i < dt.DefaultView.Count; i++)
            {
                DataRow dr = dtt.NewRow();
                dr["b_id"] = dt.Rows[i]["b_id"];
                dr["b_rid"] = dt.Rows[i]["b_rid"];
                dr["b_look"] = dt.Rows[i]["b_look"];
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_lookaddr"]) == "")
                {
                    dr["b_lookaddr"] = null;
                }
                else
                {
                    dr["b_lookaddr"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_lookaddr"]);
                }
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_branch"]) == "")
                {
                    dr["b_branch"] = null;
                }
                else
                {
                    dr["b_branch"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_branch"]);
                }
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_title"]) == "")
                {
                    dr["b_title"] = null;
                }
                else
                {
                    dr["b_title"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_title"]);
                }
                dr["b_titlelen"] = dt.Rows[i]["b_titlelen"];
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_content"]) == "")
                {
                    dr["b_content"] = null;
                }
                else
                {
                    dr["b_content"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_content"]);
                }
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_name"]) == "")
                {
                    dr["b_name"] = null;
                }
                else
                {
                    dr["b_name"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_name"]);
                }
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_tel"]) == "")
                {
                    dr["b_tel"] = null;
                }
                else
                {
                    dr["b_tel"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_tel"]);
                }
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_mail"]) == "")
                {
                    dr["b_mail"] = null;
                }
                else
                {
                    dr["b_mail"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_mail"]);
                }
                dr["b_timein"] = datatimeZH(dt.Rows[i]["b_timein"].ToString());
                dr["b_timeup"] = datatimeZH(dt.Rows[i]["b_timeup"].ToString());
                if (System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_address"]) == "")
                {
                    dr["b_address"] = null;
                }
                else
                {
                    dr["b_address"] = System.Text.Encoding.Default.GetString((byte[])dt.Rows[i]["b_address"]);
                }
                dr["b_state"] = dt.Rows[i]["b_state"];
                dr["b_reply"] = dt.Rows[i]["b_reply"];
                dr["b_replystate"] = dt.Rows[i]["b_replystate"];
                dr["b_trial"] = dt.Rows[i]["b_trial"];
                dtt.Rows.Add(dr);
            }

            BatchAdd(dtt, "l_book");
            myConnection.Close();
        }

        /// 批量添加
        public bool BatchAdd(DataTable dt, string detable)
        {
            bool flag = false;
            try
            {
                using (SqlConnection cn = new SqlConnection("server=61.136.252.201;uid=xelnage;pwd=10816555x;database=ShuJi"))
                {
                    using (System.Transactions.TransactionScope scope = new TransactionScope())
                    {
                        cn.Open();
                        using (SqlBulkCopy sbc = new SqlBulkCopy(cn))
                        {
                            //服务器上目标表的名称   
                            sbc.DestinationTableName = detable;
                            sbc.BatchSize = 1000;
                            sbc.BulkCopyTimeout = 60;

                            for (int i = 0; i < dt.Columns.Count; i++)
                            {
                                //列映射定义数据源中的列和目标表中的列之间的关系   
                                sbc.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);
                            }
                            sbc.WriteToServer(dt);
                            flag = true;
                            scope.Complete();//有效的事务   
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return flag;
        }

        // 日期时间解码
        public DateTime datatimeZH(string date)
        {
            string timeStamp = date;
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(timeStamp + "0000000");
            TimeSpan toNow = new TimeSpan(lTime);
            DateTime dtResult = dtStart.Add(toNow);
            return dtResult;
        }

        // 密码解码
        public string unpassat(string pass)
        {
            string b = "";
            for (int i = 0; i < pass.Length; i++)
            {
                char d = Convert.ToChar(pass.Substring(i, 1));
                string o = Convert.ToString((char)Asc(d, i));
                b = b + o;
            }
            return b;
        }

        /// <summary>
        /// 检查邮件地址是否正确
        /// </summary>
        /// <param name="strEmail"></param>
        /// <returns>正确返回true</returns>
        public bool CheckEmail(string strEmail)
        {
            int i, j;
            string strTmp, strResult;
            string strWords = "abcdefghijklmnopqrstuvwxyz_-.0123456789"; //定义合法字符范围

            bool blResult = false;
            strTmp = strEmail.Trim();
            //检测输入字符串是否为空，不为空时才执行代码。
            if (!(strTmp == "" || strTmp.Length == 0))
            { //判断邮件地址中是否存在“@”号
                if ((strTmp.IndexOf("@") < 0))
                {
                    blResult = true;
                    return blResult;
                }
                //以“@”号为分割符，把地址切分成两部分，分别进行验证。
                string[] strChars = strTmp.Split(new char[] { '@' });
                foreach (string strChar in strChars)
                {
                    i = strChar.Length; //“@”号前部分或后部分为空时。
                    if (i == 0)
                    {
                        blResult = true;
                        return blResult;
                    }
                    //逐个字进行验证，如果超出所定义的字符范围strWords，则表示地址非法。
                    for (j = 0; j < i; j++)
                    {

                        strResult = strChar.Substring(j, 1).ToLower();//逐个字符取出比较

                        if (strWords.IndexOf(strResult) < 0)
                        {
                            blResult = true;
                            return blResult;
                        }
                    }
                }
            }
            return blResult;
        }

        /// <summary>
        /// /// 判断是否正确电话号码
        /// /// </summary>
        /// /// <param name=”text”></param>
        /// /// <returns></returns>
        public static bool IsMobile(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }
            const string s = @"^(((1[3|5|8][0-9]{1}))+\d{8})$";
            return Regex.IsMatch(text, s);
        }

        public bool IsTelephone(string str_telephone)
        {
            return Regex.IsMatch(str_telephone, @"^\d{3,4}-?\d{7,8}$");
        }

        public static int Asc(char character, int i)
        {
            int asc = Convert.ToInt32(character) - i - 1;
            return asc;
        }

        public static void clearSQLTable(string tablename)
        {
            SqlConnection cn = new SqlConnection("server=61.136.252.201;uid=xelnage;pwd=10816555x;database=ShuJi");
            cn.Open();
            SqlCommand cmd = new SqlCommand("TRUNCATE TABLE " + tablename, cn);
            cmd.ExecuteNonQuery();
            cn.Close();
        }

        public int getreid(string reid)
        {
            DataRow dr = SQL.GetList("B_ask", "t_id = '" + reid + "'", "a_id").Tables[0].Rows[0];
            return Convert.ToInt32(dr.ItemArray[0]);
        }

        public int nicktoid(string usernick, string level)
        {
            DataRow dr = SQL.GetList("B_user", "u_nickName = '" + usernick + "' and u_level = '" + level + "'", "u_id").Tables[0].Rows[0];
            return Convert.ToInt32(dr.ItemArray[0]);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            // 转换book表;
            clearSQLTable("l_book");
            databook();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            // 转换user表;
            clearSQLTable("l_user");
            datauser();
        }

        //导入用户
        protected void Button3_Click(object sender, EventArgs e)
        {
            function make_htm = new function();//继承类

            clearSQLTable("B_user");

            //添加tmwcn账户
            string addtmwcn = "insert into B_user(u_email,u_passWord,u_phone,u_nickName,u_askNumber,u_reviewNumber,u_goodNumber,u_regTime,u_point,u_img,u_level,u_ischeck) values(";
            addtmwcn += "@u_email,@u_passWord,@u_phone,@u_nickName,@u_askNumber,@u_reviewNumber,@u_goodNumber,@u_regTime,@u_point,@u_img,@u_level,@u_ischeck)";
            SqlParameter[] tmwcnpart = new SqlParameter[]{
            new SqlParameter("@u_email", "admin@tmwcn.com"),
            new SqlParameter("@u_passWord", make_htm.Md5("10816555")),
            new SqlParameter("@u_phone", "0728-5222111"),
            new SqlParameter("@u_nickName", "问友"),
            new SqlParameter("@u_askNumber", "0"),
            new SqlParameter("@u_reviewNumber", "0"),
            new SqlParameter("@u_goodNumber", "0"),
            new SqlParameter("@u_regTime", "2001-01-01 01:01:01.000"),
            new SqlParameter("@u_point", "0"),
            new SqlParameter("@u_img", alldata.Config_defaultimg),
            new SqlParameter("@u_level", "1"),
            new SqlParameter("@u_ischeck", "0")
        };
            SQL.Add(addtmwcn, tmwcnpart);

            //导入普通用户
            DataRow dr = SQL.GetList("l_book", "b_rid=0", "b_name, b_tel, b_mail, b_timein").Tables[0].Rows[0];
            for (int i = 0; i < dr.Table.Rows.Count; i++)
            {
                string email = dr.Table.Rows[i]["b_mail"].ToString().ToLower();
                string phone = dr.Table.Rows[i]["b_tel"].ToString();
                if (email != null && email != "")
                {
                    DataTable dt = SQL.GetList("B_user", "u_email='" + email + "'", "u_email").Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                    }
                    else
                    {
                        if (CheckEmail(email))
                        {
                        }
                        else
                        {
                            if (phone == null && phone == "")
                            {
                                phone = "12345678";
                            }

                            //导入用户
                            string rsql = "insert into B_user(u_email,u_passWord,u_phone,u_nickName,u_askNumber,u_reviewNumber,u_goodNumber,u_regTime,u_point,u_img,u_level,u_ischeck) values(";
                            rsql += "@u_email,@u_passWord,@u_phone,@u_nickName,@u_askNumber,@u_reviewNumber,@u_goodNumber,@u_regTime,@u_point,@u_img,@u_level,@u_ischeck)";
                            SqlParameter[] rparameters = new SqlParameter[]{
                            new SqlParameter("@u_email", email),
                            new SqlParameter("@u_passWord", make_htm.Md5("a1b2c3")),
                            new SqlParameter("@u_phone", phone),
                            new SqlParameter("@u_nickName", dr.Table.Rows[i]["b_name"].ToString()),
                            new SqlParameter("@u_askNumber", "0"),
                            new SqlParameter("@u_reviewNumber", "0"),
                            new SqlParameter("@u_goodNumber", "0"),
                            new SqlParameter("@u_regTime", dr.Table.Rows[i]["b_timein"]),
                            new SqlParameter("@u_point", "0"),
                            new SqlParameter("@u_img", alldata.Config_defaultimg),
                            new SqlParameter("@u_level", "1"),
                            new SqlParameter("@u_ischeck", "0")
                        };
                            SQL.Add(rsql, rparameters);
                        }
                    }
                }
                else
                {
                }
            }

            DataRow admindr = SQL.GetList("l_user", "u_order<>0", "u_id, u_branch, u_pass").Tables[0].Rows[0];
            for (int i = 0; i < admindr.Table.Rows.Count; i++)
            {
                string u_email = "tmask_" + admindr.Table.Rows[i]["u_id"].ToString() + "@tmwcn.com";
                string u_phone = "0728-" + admindr.Table.Rows[i]["u_id"].ToString();
                //导入用户
                string adminrsql = "insert into B_user(u_email,u_passWord,u_phone,u_nickName,u_askNumber,u_reviewNumber,u_goodNumber,u_regTime,u_point,u_img,u_level,u_ischeck,b_id) values(";
                adminrsql += "@u_email,@u_passWord,@u_phone,@u_nickName,@u_askNumber,@u_reviewNumber,@u_goodNumber,@u_regTime,@u_point,@u_img,@u_level,@u_ischeck,@b_id)";
                SqlParameter[] adminrparameters = new SqlParameter[]{
                new SqlParameter("@u_email", u_email),
                new SqlParameter("@u_passWord", make_htm.Md5(admindr.Table.Rows[i]["u_pass"].ToString())),
                new SqlParameter("@u_phone", u_phone),
                new SqlParameter("@u_nickName", admindr.Table.Rows[i]["u_branch"].ToString()),
                new SqlParameter("@u_askNumber", "0"),
                new SqlParameter("@u_reviewNumber", "0"),
                new SqlParameter("@u_goodNumber", "0"),
                new SqlParameter("@u_regTime", "2001-01-01 01:01:01.000"),
                new SqlParameter("@u_point", "0"),
                new SqlParameter("@u_img", alldata.Config_defaultimg),
                new SqlParameter("@u_level", "8"),
                new SqlParameter("@u_ischeck", "0"),
                new SqlParameter("@b_id", admindr.Table.Rows[i]["u_id"].ToString())

            };
                SQL.Add(adminrsql, adminrparameters);
            }

        }

        //导入提问和回复
        protected void Button4_Click(object sender, EventArgs e)
        {
            clearSQLTable("b_ask");
            clearSQLTable("b_review");

            DataRow dr = SQL.GetList("l_book", "b_rid=0", "b_id, b_content, b_title, b_branch, b_reply, b_timein, b_name, b_mail, b_look, b_state, b_replystate, b_address").Tables[0].Rows[0];
            for (int i = 0; i < dr.Table.Rows.Count; i++)
            {

                string a_title = dr.Table.Rows[i]["b_title"].ToString();
                string a_content = function.HTMLEncode(dr.Table.Rows[i]["b_content"].ToString());

                // 查找用户Id
                int u_id;
                DataTable maildt = SQL.GetList("B_user", "u_email='" + dr.Table.Rows[i]["b_mail"].ToString() + "'", "u_id, u_email").Tables[0];
                if (maildt.Rows.Count > 0)
                {
                    u_id = Convert.ToInt16(maildt.Rows[0]["u_id"]);
                }
                else
                {
                    DataTable uid_dt = SQL.GetList("B_user", "u_nickName='" + dr.Table.Rows[i]["b_name"].ToString() + "'", "u_id, u_nickName").Tables[0];
                    if (uid_dt.Rows.Count > 0)
                    {
                        u_id = Convert.ToInt16(uid_dt.Rows[0]["u_id"]);
                    }
                    else
                    {
                        u_id = 1;
                    }
                }

                int a_reviewNumber = Convert.ToInt32(dr.Table.Rows[i]["b_reply"]);
                DateTime a_time = Convert.ToDateTime(dr.Table.Rows[i]["b_timein"]);
                int a_state = 0;

                int a_classid = getclassid(dr.Table.Rows[i]["b_branch"].ToString());

                int a_classLevel = Convert.ToInt32(SQL.GetList("select a_classLevel from B_askClass where a_classid=" + a_classid).Tables[0].Rows[0]["a_classLevel"]);

                int a_hitNumber = Convert.ToInt32(dr.Table.Rows[i]["b_look"]);
                int a_ischeck;
                if (dr.Table.Rows[i]["b_state"].ToString() == "1")
                {
                    a_ischeck = 0;
                }
                else
                {
                    a_ischeck = 1;
                }
                int a_delete = 0;
                int a_hiddenuser = 0;
                int a_recommend = 0;
                string a_ip = dr.Table.Rows[i]["b_address"].ToString();

                string t_id = dr.Table.Rows[i]["b_id"].ToString();

                string sqlask = "insert into b_ask(a_title,a_content,u_id,a_reviewNumber,a_time,a_state,a_classid,a_classLevel,a_hitNumber,a_ischeck,a_delete,a_hiddenuser,a_recommend,a_ip,t_id) values(";
                sqlask += "@a_title,@a_content,@u_id,@a_reviewNumber,@a_time,@a_state,@a_classid,@a_classLevel,@a_hitNumber,@a_ischeck,@a_delete,@a_hiddenuser,@a_recommend,@a_ip,@t_id)";
                SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@a_title",a_title),
                new SqlParameter("@a_content",function.HTMLEncode(a_content)),
                new SqlParameter("@u_id",u_id),
                new SqlParameter("@a_reviewNumber",a_reviewNumber),
                new SqlParameter("@a_time",a_time),
                new SqlParameter("@a_state",a_state),
                new SqlParameter("@a_classid",a_classid),
                new SqlParameter("@a_classLevel",a_classLevel),
                new SqlParameter("@a_hitNumber",a_hitNumber),
                new SqlParameter("@a_ischeck",a_ischeck),
                new SqlParameter("@a_delete",a_delete),
                new SqlParameter("@a_hiddenuser",a_hiddenuser),
                new SqlParameter("@a_recommend",a_recommend),
                new SqlParameter("@a_ip",a_ip),
                new SqlParameter("@t_id",t_id)
            };
                SQL.Add(sqlask, param);

                DataTable redr = SQL.GetList("l_book", "b_rid<>0 and b_rid = '" + t_id + "'", "b_id, b_rid, b_content, b_title, b_branch, b_reply, b_timein, b_name, b_mail, b_look, b_state, b_replystate, b_address").Tables[0];
                for (int j = 0; j < redr.Rows.Count; j++)
                {
                    string r_content = redr.Rows[j]["b_content"].ToString();
                    string r_time = redr.Rows[j]["b_timein"].ToString();
                    int a_id = getreid(redr.Rows[j]["b_rid"].ToString());
                    int r_isGood = 0;
                    int r_agreeNumber = 0;
                    int r_unagreeNumber = 0;

                    // 查找用户Id
                    int r_userid;
                    DataTable userdt = SQL.GetList("B_user", "u_level = 8 and u_nickName='" + redr.Rows[j]["b_branch"].ToString() + "'", "u_nickName, u_email, b_id").Tables[0];
                    if (userdt.Rows.Count > 0)
                    {
                        r_userid = nicktoid(userdt.Rows[0]["u_nickName"].ToString(), "8");
                    }
                    else
                    {
                        r_userid = 1;
                    }

                    int r_hiddenuser = 0;

                    //增加回复记录
                    string rsql = "insert into B_review(r_content,r_time,a_id,r_isGood,r_agreeNumber,r_unagreeNumber,r_userid,r_hiddenuser) values(";
                    rsql += "@r_content,@r_time,@a_id,@r_isGood,@r_agreeNumber,@r_unagreeNumber,@r_userid,@r_hiddenuser)";
                    SqlParameter[] rparameters = new SqlParameter[]{
                    new SqlParameter("@r_content", function.HTMLEncode(r_content)),
                    new SqlParameter("@r_time", r_time),
                    new SqlParameter("@a_id", a_id),
                    new SqlParameter("@r_isGood", r_isGood),
                    new SqlParameter("@r_agreeNumber", r_agreeNumber),
                    new SqlParameter("@r_unagreeNumber", r_unagreeNumber),
                    new SqlParameter("@r_userid", r_userid),
                    new SqlParameter("@r_hiddenuser", r_hiddenuser),
                };
                    SQL.Add(rsql, rparameters);

                }

            }
        }

        // 效验主题回复数量;
        protected void Button5_Click(object sender, EventArgs e)
        {
            DataTable lc = SQL.GetList("SELECT a_id, u_id, a_reviewNumber FROM b_ask").Tables[0];
            for (int j = 0; j < lc.DefaultView.Count; j++)
            {
                DataTable reviewnum = SQL.GetList("SELECT * FROM B_review WHERE a_id = '" + lc.Rows[j]["a_id"].ToString() + "'").Tables[0];
                SQL.ExecuteSql("update b_ask set a_reviewNumber='" + reviewnum.DefaultView.Count + "' where a_id='" + lc.Rows[j]["a_id"].ToString() + "'");
            }
        }

        // 效验分类主题数量;
        protected void Button6_Click(object sender, EventArgs e)
        {
            DataTable lc = SQL.GetList("SELECT a_classid FROM b_askClass WHERE a_classLevel = 2").Tables[0];
            for (int j = 0; j < lc.DefaultView.Count; j++)
            {
                string count = SQL.GetListcount("b_ask", "a_classid=" + lc.Rows[j]["a_classid"].ToString()).ToString();
                SQL.ExecuteSql("update b_askClass set a_askCount='" + count + "' where a_classid='" + lc.Rows[j]["a_classid"].ToString() + "'");
            }
        }

        // 效验用户主题回复数;
        protected void Button7_Click(object sender, EventArgs e)
        {
            DataTable lc = SQL.GetList("SELECT u_id FROM b_user").Tables[0];
            for (int j = 0; j < lc.DefaultView.Count; j++)
            {
                //string count = SQL.GetListcount("b_ask", "u_id=" + lc.Rows[j]["u_id"].ToString()).ToString();
                //SQL.ExecuteSql("update b_user set u_askNumber='" + count + "' where u_id='" + lc.Rows[j]["u_id"].ToString() + "'");

                string count2 = SQL.GetListcount("b_review", "r_userid=" + lc.Rows[j]["u_id"].ToString()).ToString();
                SQL.ExecuteSql("update b_user set u_reviewNumber='" + count2 + "' where u_id='" + lc.Rows[j]["u_id"].ToString() + "'");

            }
        }
    }
}